/*
 * ******************************************************************************
 *   Copyright (c) 2013-2014 Gabriele Mariotti.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *  *****************************************************************************
 */

package it.gmariotti.cardslib.demo.cards;

import it.gmariotti.cardslib.demo.ResourceTable;
import it.gmariotti.cardslib.library.Constants;
import it.gmariotti.cardslib.library.internal.Card;
import it.gmariotti.cardslib.library.utils.PixelMapUtils;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.Rating;
import ohos.agp.components.Text;
import ohos.app.Context;
import ohos.hiviewdfx.HiLog;

/**
 * This class provides an example of custom card with a custom inner layout.
 *
 * @author Gabriele Mariotti (gabri.mariotti@gmail.com)
 */
public class CustomCard extends Card {

    protected Text mTitle;
    protected Text mSecondaryTitle;
    protected Rating mRatingBar;

    /**
     * Constructor with a custom inner layout
     *
     * @param context
     */
    public CustomCard(Context context) {
        this(context, ResourceTable.Layout_carddemo_mycard_inner_content);
    }

    /**
     * @param context
     * @param innerLayout
     */
    public CustomCard(Context context, int innerLayout) {
        super(context, innerLayout);
        init();
    }

    /**
     * Init
     */
    private void init() {

        //No Header

        /*
        //Set a OnClickListener listener
        setClickedListener(new OnCardClickListener() {
            @Override
            public void onClick(Card card, Component view) {
                Toast.makeText(getContext(), "Click Listener card=", Toast.LENGTH_LONG).show();
            }
        });*/
    }

    @Override
    public void setupInnerViewElements(ComponentContainer parent, Component view) {

        //Retrieve elements
        mTitle = (Text) parent.findComponentById(ResourceTable.Id_carddemo_myapps_main_inner_title);
        mSecondaryTitle = (Text) parent.findComponentById(ResourceTable.Id_carddemo_myapps_main_inner_secondaryTitle);
        mRatingBar = (Rating) parent.findComponentById(ResourceTable.Id_carddemo_myapps_main_inner_ratingBar);


        if (mTitle != null)
            mTitle.setText(ResourceTable.String_demo_custom_card_google_maps);

        if (mSecondaryTitle != null)
            mSecondaryTitle.setText(ResourceTable.String_demo_custom_card_googleinc);

        if (mRatingBar != null) {
//            mRatingBar.setNumStars(5);
//            mRatingBar.setMax(5);
//            mRatingBar.setStepSize(0.5f);
//            mRatingBar.setRating(4.7f);
            try {
                mRatingBar.setFilledElement(PixelMapUtils.prepareElementById(getContext(), ResourceTable.Media_rate_star_small_on_holo_dark));
                mRatingBar.setUnfilledElement(PixelMapUtils.prepareElementById(getContext(), ResourceTable.Media_rate_star_small_off_holo_dark));
                mRatingBar.setHalfFilledElement(PixelMapUtils.prepareElementById(getContext(), ResourceTable.Media_rate_star_small_half_holo_dark));
                mRatingBar.setRatingItems(5);
                mRatingBar.setMaxValue(5);
                mRatingBar.setGrainSize(0.5f);
                mRatingBar.setScore(4.7f);
            } catch (Exception e) {
                HiLog.error(Constants.LABEL_LOG, e.toString());
            }
        }

    }
}
